﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FillMatrixVariant2
{
    class FillMatrixVariant1B
    {
        static void Main(string[] args)
        {

            Console.Write("n=");
            int n = int.Parse(Console.ReadLine());
            int[,] matrix = new int[n, n];

            int count = 1;
            for (int i = 0; i < n; i++) //columns
            {
                if (i % 2 == 0)
                {
                    for (int y = 0; y < n; y++) //rows count down
                    {
                        matrix[y, i] = count++;
                    }
                }
                else
                {
                    for (int y = n - 1; y >= 0; y--) //rows count up
                    {
                        matrix[y, i] = count++;
                    }
                }
            }
            Console.WriteLine();
        	for (int i = 0; i < n; i++)
        	{
        	    for (int y = 0; y < n; y++)
        	    {
        	        Console.Write("{0, 4}",matrix[i,y]);
        	    }
        	    Console.WriteLine();
        	}
        }
    }
}
            /*for (int row = 0, number=row+1; row < n; number++, row++)
            {
                matrix[row, 0] = number;
            }
            for (int number = 2*n, row=0; number > n; number--, row++)
            {
                matrix[row, 1] = number;
            }
            for (int number = 2 * n+1, row = 0; number <= 3*n; number++, row++)
            {
                matrix[row, 2] = number;
            }
            for (int number = 4 * n, row = 0; number >3* n; number--, row ++)
            {
                matrix[row, 3] = number;
            }
             * /*///row,col
            // [0, 0] = 1 [0, 1] = 8 [0, 2] = 9 
            // [1, 0] = 2 [0, 2] = 7 [1, 2] = 10
            // [2, 0] = 3 [0, 3] = 6 [2, 2] = 11
            // [3, 0] = 4 [0, 4] = 5 [3, 2] = 12
            // universal 
            /*for (int row = 0; row < n; row++)
            {
                for (int col = 0, number = col + 1; col < n; number++, col++)
                {
                    matrix[col, 0] = number;
                }

                for (int number = 2 * n, col = 0; number > n; number--, col++)
                {
                    matrix[col, 1] = number;
                }

            }
            //printing
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(matrix[i,j]+" ");
                }
                Console.WriteLine();
            }
            /*for (int row = 0; row < n; row++)
            {

                for (int col = row + 1; col <= n * n; col += 4)
                {
                    Console.Write(col + " ");
                }
                Console.WriteLine();
            }/*/